package org.template.dao;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.template.dao.iter.RedisDelegator;
import org.template.dao.iter.RedisDelegatorNoResult;

import redis.clients.jedis.Jedis;

@Repository
public class SetRedisDao extends BaseRedisDao {

	
	public long getSize(final String key){
		
		return run(new RedisDelegator<Long>() {
			@Override
			public Long execute(Jedis redis) {
				return redis.scard(key);
			}
		});
	}
	
public void addElement(final String key,final String... members){
		
		runNoResult(new RedisDelegatorNoResult() {
			@Override
			public void execute(Jedis redis) {
				redis.sadd(key, members);
			}
		});
		
	}
	public void removeElement(final String key,final String ...members){
		
		
		runNoResult(new RedisDelegatorNoResult() {
			@Override
			public void execute(Jedis redis) {
				redis.srem(key, members);
			}
		});
		
	}
	
	public List<String> getElementRandom(final String key,final int count){
		
		
		return run(new RedisDelegator<List<String>>() {
			@Override
			public List<String> execute(Jedis redis) {
				return redis.srandmember(key, count);
			}
		});
		
	}
}
